package cn.credit.loan.controller;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.credit.loan.entity.Card;
import cn.credit.loan.service.card.CardService;

@Controller
public class CardController {
		//日志输出
		private Logger logger = Logger.getLogger(CardController.class);
		@Autowired
		private CardService cardService;
		
		/**
		 * 卡通添加
		 * @param card
		 * @param model
		 * @return
		 */
		@RequestMapping("/cardadd")
		public String getCardAdd(Card card,ModelMap model)
		{
			try {
			
				card.setCardNmuber("1234567899876543210");
				card.setCardPwd("123456");
				card.setCardMoney(40000.00);
				card.setCardBalance(3999.00);
				card.setCardDeposit(3000.00);
				card.setCardDepositDate(new Date());
				card.setCardWithdrawal(2000.00);
				card.setCardWithdrawalDate(new Date());
				boolean cards=cardService.getCardadd(card);
				if(cards)
				{
					model.addAttribute("card", card);
					return "CardAdd";
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return null;
			
		}
		
		/**
		 * 卡通更新
		 * @param card
		 * @param model
		 * @return
		 */
		@RequestMapping("/cardupdate")
		public String getCardUpdate(Card card,ModelMap model)
		{
			try {
				card.setLoanId(4);
				card.setCardNmuber("1234567899876543210");
				card.setCardPwd("123456");
				card.setCardMoney(40000.00);
				card.setCardBalance(3999.00);
				card.setCardDeposit(3000.00);
				card.setCardDepositDate(new Date());
				card.setCardWithdrawal(2000.00);
				card.setCardWithdrawalDate(new Date());
				boolean cards=cardService.getCardupdate(card);
				if(cards)
				{
					model.addAttribute("card", card);
					return "CardUpdate";
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return null;
			
		}
		
		/**
		 * 卡通删除
		 * @param card
		 * @param model
		 * @return
		 */
		@RequestMapping("/carddelete")
		public String getCardDelete(int cardId,ModelMap model)
		{
			try {
				
				boolean cards=cardService.getCarddelete(cardId);
				if(cards)
				{
					model.addAttribute("cardId", cardId);
					return "CardDelete";
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return null;
			
		}
		
		/**
		 * 卡通查询
		 * @param card
		 * @param model
		 * @return
		 */
		@RequestMapping(value="/cardlist")
		@ResponseBody
		public Object getCardList(Card card,ModelMap model)
		{
			try {
				List<Card> cardlist=cardService.getCardList(card);
				if(cardlist!=null)
				{
					model.addAttribute("card", card);
					return cardlist;
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return model;
			
		}
}
